<template>
  <h3 style="margin-bottom: 20px">员工编辑</h3>

  <el-form
      ref="ruleFormRef"
      :model="employee"
      label-width="120px"
      style="width: 600px;"
  >
    <el-form-item label="姓名">
      <el-input v-model="employee.name"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-input v-model="employee.sex"></el-input>
    </el-form-item>
    <el-form-item label="生日">
      <el-date-picker v-model="employee.birthday" style="width: 500px"></el-date-picker>
    </el-form-item>
    <el-form-item label="职位">
      <el-input v-model="employee.job"></el-input>
    </el-form-item>
    <el-form-item label="基本薪资">
      <el-input v-model="employee.baseSalary"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
import {ref} from "vue";
import say from "../../util/say";
import {Fetch} from "../../api/request";


let ruleFormRef = ref(null);
let employee = ref({
  name: null,
  sex: null,
  birthday: null,
  job: null,
  baseSalary: null,
  entryTime: null
});

const submitForm = async (formElement) => {
  if (!formElement) return
  await formElement.validate(async (valid) => {
    if (valid) {
      Fetch.post('/employee/save', employee.value).then(response => {
        if (response.ok) {
          say.saySuccess('保存成功')
        } else {
          say.sayError('保存失败')
        }
      }).catch(_ => {
        say.sayError('保存失败')
      });
    } else {
      say.sayError('保存失败')
    }
  })
}
</script>

<style scoped>

</style>